package com.bjsxt;

import com.bjsxt.service.OrderService;
import io.seata.core.context.RootContext;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("com.bjsxt.mapper")
@RestController
@EnableFeignClients
public class OrderServiceApplication {

    @Autowired
    private OrderService orderService ;

    public static void main(String[] args) {
        SpringApplication.run(OrderServiceApplication.class,args) ;
    }

    @GetMapping("/create/{userId}/{productNo}/{count}")
    public ResponseEntity<Void> createOrder(
            @PathVariable("userId") String userId ,
            @PathVariable("productNo") String productNo ,
            @PathVariable("count") Integer count
    ){

        String xid = RootContext.getXID();
        System.out.println("全局的事务id:"+xid);
        orderService.createOrder(userId,productNo,count) ;
        return ResponseEntity.ok().build() ;
    }
}
